import "./assets/main.css"

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'

import App from './App.vue'
import router from './router'
import axios from 'axios'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

const app = createApp(App)

// 配置axios
axios.defaults.baseURL = '/api'
axios.interceptors.request.use(config => {
  // 可以在这里添加token等认证信息
  return config
})

axios.interceptors.response.use(response => {
  return response.data
}, error => {
  console.error('API请求失败（预期行为，使用模拟数据）:', error.message)
  // 返回resolve而不是reject，允许页面继续使用模拟数据
  return Promise.resolve({}) 
})

app.use(ElementPlus, {
    locale: zhCn,
})
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app.use(createPinia())
app.use(router)
app.config.globalProperties.$axios = axios

app.mount('#app')
